package com.hzbat.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzbat.entity.PmHzbatSchedule;
import com.hzbat.response.DataResponse;
import com.hzbat.service.PmHzbatScheduleService;

/***
 * 访问主页
 * @author yf141
 *
 */

@Controller
@RequestMapping("index")
public class IndexController extends BasicController{

	
	@Autowired
	PmHzbatScheduleService pmHzbatScheduleServiceImpl ;	
	
	/***
	 * 跳转到主页面
	 */
	@RequestMapping()
	public String toMain(Model model){
		//计划列表
		List<PmHzbatSchedule> list = pmHzbatScheduleServiceImpl.getList(null);
		model.addAttribute("pmHzbatScheduleList", list);
		return "index/main";
	}
	
	
	/***
	 * 跳转到计划模板界面
	 * @param dagSchedule
	 * @param model
	 * @return
	 */
	@RequestMapping("schedule")
	public String toSchedule(PmHzbatSchedule pmHzbatSchedule,Model model){
	
		try {
			if(pmHzbatSchedule.getScheduleDesc()!=null && !"".equals(pmHzbatSchedule.getScheduleDesc())){
			String getScheduleDesc = java.net.URLEncoder.encode(pmHzbatSchedule.getScheduleDesc(),"ISO-8859-1");
			String getScheduleDesc1 = java.net.URLDecoder.decode(getScheduleDesc,"utf-8");
			pmHzbatSchedule.setScheduleDesc(getScheduleDesc1);
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		model.addAttribute("pmHzbatSchedule", pmHzbatSchedule);
		return "schedule/schedule_template";
		
	}
	
	/***
	 * 跳转到计划模板编辑界面
	 * @param pmHzbatSchedule
	 * @param model
	 * @return
	 */
	@RequestMapping("scheduleCompile")
	public String toScheduleCompile(PmHzbatSchedule pmHzbatSchedule,Model model){
		try {
			if(pmHzbatSchedule.getScheduleDesc()!=null && !"".equals(pmHzbatSchedule.getScheduleDesc())){
			String getScheduleDesc = java.net.URLEncoder.encode(pmHzbatSchedule.getScheduleDesc(),"ISO-8859-1");
			String getScheduleDesc1 = java.net.URLDecoder.decode(getScheduleDesc,"utf-8");
			pmHzbatSchedule.setScheduleDesc(getScheduleDesc1);
			}
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		model.addAttribute("pmHzbatSchedule", pmHzbatSchedule);
		return "schedule/schedule_template_compile";
		
	}
	
	
	/***
	 * 刷新计划列表菜单
	 * @param dagSchedule
	 * @return
	 */
	@ResponseBody
	@RequestMapping("flushDynamicMenu")
	public DataResponse<List<PmHzbatSchedule>> flushDynamicMenu(PmHzbatSchedule pmHzbatSchedule){
		List<PmHzbatSchedule> data = pmHzbatScheduleServiceImpl.getList(pmHzbatSchedule);	                          
		DataResponse<List<PmHzbatSchedule>> response = new DataResponse<List<PmHzbatSchedule>>();	      
		response.setData(data);		                                                      
		return response ;	
	}
	
}





